<template>
  <px-dialog v-model="visible" title="智能分析报告" @close="cancel">
    <div v-loading="loading" class="report-container">
      <px-descriptions :column="1" border>
        <px-descriptions-item label="诊断结论">
          {{ conclusion }}
        </px-descriptions-item>
        <px-descriptions-item label="诊断原因">
          {{ reason }}
        </px-descriptions-item>
      </px-descriptions>
    </div>
  </px-dialog>
</template>

<script setup>
import { ref, reactive, onMounted, computed, toRefs } from "vue";
import { getAnalysisReportAPI } from "@/api/energy/monitor";

const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  rowData: {
    type: Object,
    default: () => {}
  }
});
const emits = defineEmits(["update:visible"]);

const state = reactive({
  loading: false,
  conclusion: "",
  reason: ""
});
const { loading, conclusion, reason } = toRefs(state);

onMounted(() => {
  getAnalysisData();
});

const getAnalysisData = async () => {
  try {
    state.loading = true;
    const params = {
      id: props.rowData.id
    };
    await getAnalysisReportAPI(params);
  } catch (err) {
    console.log(err);
  } finally {
    state.loading = false;
  }
};

const visible = computed({
  get: () => props.visible,
  set: val => emits("update:visible", val)
});

const cancel = () => {
  emits("update:visible", false);
};
</script>

<style lang="scss" scoped>
.report-container {
  width: 100%;
  overflow-y: auto;
}

.info-line {
  display: flex;
  margin-bottom: 16px;
  color: #000;

  .label {
    width: 100px;
    padding: 0 8px;
    margin-right: 8px;
    text-align: right;
  }

  .content {
    flex: 1;
  }
}

:deep(.px-descriptions__label) {
  width: 100px;
}
</style>
